/**
 * Created by wangshaohua on 16/1/19.
 */
var sz_RequestHelper = {};

sz_RequestHelper.addParam = function (uri, key, value) {
    if (sz_RequestHelper.getParameter(key)) {
        return uri;
    }
    if (uri.indexOf('?') > 0) {
        uri = uri + "&" + key + "=" + value;
    } else {
        uri = uri + "?" + key + "=" + value;
    }
    return uri;
}

sz_RequestHelper.getParameter = function (key) {
    var paramsStr;
    if (sz_StringHelper.isNotEmpty(window.location.href) && window.location.href.indexOf("?") > -1) {
        paramsStr = window.location.href;
    }

    if (!paramsStr) {
        paramsStr = window.location.hash;
    }
    if (!paramsStr) {
        paramsStr = window.location.search;
    }
    if (!paramsStr) {
        paramsStr = "";
    }

    if (paramsStr.indexOf("?") > -1) {
        paramsStr = paramsStr.substr(paramsStr.indexOf("?") + 1);
        var reqValue = paramsStr.split("&");
        for (var i = 0; i < reqValue.length; i++) {
            if (key == reqValue[i].split("=")[0]) {
                return reqValue[i].split("=")[1];
            }
        }
        return null;
    } else {
        return null;
    }
}

sz_RequestHelper.getQueryStringFromUrl = function (url, name) {
    var reg = new RegExp("(^|&?)" + name + "=([^&]*)(&|$)", "i");
    var r = url.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}

sz_RequestHelper.getLoadJsUrl = function () {
    var js = document.getElementsByTagName("script");
    for (var i = 0; i < js.length; i++) {
        if (js[i].src.indexOf("thrid-party-js") > 0) {
            return js[i].src;
        }
    }
}